import 'package:flutter/material.dart';

class StatefulGroup extends StatefulWidget {
  @override
  _StatefulGroupState createState() => _StatefulGroupState();
}

class _StatefulGroupState extends State<StatefulGroup> {
  var _index = 0;
  var _images0 = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1587063558785&di=2dc18477e1445788a6694690f853d233&imgtype=0&src=http%3A%2F%2Fimg1.gtimg.com%2F16%2F1649%2F164972%2F16497298_1200x1000_0.jpg';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("StatefulGroup"),
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _index,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text("主页"),
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.access_time), title: Text("时间"))
          ],
          onTap: (index) {
            setState(() {
              _index = index;
            });
          },
        ),
        body: _index == 0
            ? RefreshIndicator(
            child: ListView(
              children: <Widget>[
                Image.network(_images0)
              ],
            ),
            onRefresh: _getData)
            : Text("data"),
      );
  }

  Future<Null> _getData() async {
    await Future.delayed(Duration(seconds: 3));
    setState(() {
      _images0 = 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3742646121,373871540&fm=26&gp=0.jpg';
    });
    return null;
  }
}
